<?php
/**
 * theme : default
 * description : contact
 * author : Gmax
 */

// récupération de la cible
$target = navigation::getTarget();
$article = null;

$topImage = $target->getMedia();
if($target->type==='publication'||$target->type==='page') $article=$target;
$category = navigation::getCategory();
$posts = $this->getPublications();

$msg = '';
/* Traitement du formulaire */
if( isset($_POST) && isset($_POST['message']) && trim($_POST['message']) != '' && trim($_POST['sujet_contact']) != '' ){
    $content = '<p>Sujet : '.$_POST['sujet_contact'].'</p>';
    $content .= '<p>Message :<br/>'.nl2br($_POST['message']).'</p>';
    $demandeur = new modele_user();
    $datasDemandeur = $_POST;
    $demandeur->setDatas($datasDemandeur);
    mailer::sendMail('contact', $demandeur, $content);
    $msg = '<span class="rouge">Votre demande a été transmise.</span>';
    $_POST = array();
}elseif(isset($_POST) && isset($_POST['submit'])){
    $msg = '<span class="rouge">Tous les champs sont obligatoires</span>';
}
?>
<?php if(isset($topImage)&&$topImage!==null&&$topImage->getHeight()>0): ?>
<div class="top-image">
    <img src="<?php echo $topImage->getUrl(); ?>" width="<?php echo $topImage->getWidth(); ?>" alt="<?php echo $topImage->getLegende(); ?>" title="<?php echo $topImage->getTitle(); ?>"/>
</div>
<?php else: ?>
<div class="spacer">&nbsp;</div>
<?php endif; ?>
<div id="content" class="container">
    <article><div class="article">
        <div class="columns eight">
            <h1 class="title violet"><?php if($category!==null): ?><?php echo $category->getTitle(); ?><?php endif; ?></h1>
    <?php if(count($posts)>0): ?>
        <?php foreach( $posts as $oPost ): ?>
        <?php $post = $oPost->getDatas(); ?>
            <div class="post-content">
                <?php echo $post['content']; ?>
            </div>
            <div class="clear">&nbsp;</div>
        <?php endforeach; ?>
    <?php endif; ?>
        </div>
        <div class="columns eight">
            <div id="form_contact" >
                <h2 class="vert">Formulaire contact</h2>
                <form class="form_user" name="support" method="post" enctype="application/x-www-form-urlencoded">
                    <p class="norm_label"><label><strong>Nom* :</strong></label><input type="text" name="nom" value="<?php echo (isset($_POST)&&isset($_POST['nom'])&&trim($_POST['nom']!==''))?$_POST['nom']:''; ?>" /></p>
                    <p class="norm_label"><label><strong>Prénom :</strong></label><input type="text" name="prenom"  value="<?php echo (isset($_POST)&&isset($_POST['prenom'])&&trim($_POST['prenom']!==''))?$_POST['prenom']:''; ?>" /></p>
                    <p class="norm_label"><label><strong>Téléphone :</strong></label><input type="text" name="phone1" id="phone" value="<?php echo (isset($_POST)&&isset($_POST['phone'])&&trim($_POST['phone']!==''))?$_POST['phone']:''; ?>" /></p>
                    <p class="norm_label"><label><strong>Votre adresse e-mail* : </strong></label><input type="text" name="email" id="email" value="<?php echo (isset($_POST)&&isset($_POST['email'])&&trim($_POST['email']!==''))?$_POST['email']:''; ?>" /></p>
                    <p class="norm_label"><label class="support"><strong>Votre message* : </strong></label><textarea name="message" class="message_support"></textarea></p>
                    <p class="bottom_form"><span class="nota">* champs obligatoires.</span></p>
                    <p class="bottom_form" align="right"><input type="submit" class="send_contact cap blanc" value="envoyer"/></p>
                    <input type="hidden" name="sujet_contact" value="demande de contact depuis le site <?php echo $this->getBaseUrl(); ?>" />
                </form>
                <?php if($msg!=='') echo '<h4 align="center" class="cap bold vert">'.$msg.'</h4>'; ?>
            </div>
        </div>
    </div></article>
    <div class="endArticle">&nbsp;</div>
</div>